[#ftl]

[#--
 * 功能：列表是否存在某个值
--]
[#function contains list item]
    [#list list as nextInList]
    	[#if nextInList == item][#return true][/#if]
    [/#list]
    [#return false]
[/#function]

[#--
 * 功能：返回rvdict
 * 例子： ${c.dict("common.sex").name}
--]
[#function dict code]
	[#local element=rvdict.get(code)]
	[#if element??]
		[#return element.value/]
	[/#if]
[/#function]
[#--
 * 功能：返回rvconfig
 * 例子： ${c.config("email.account").name}
--]
[#function config code]
	[#local element=rvconfig.get(code)]
	[#if element??]
		[#return element.value/]
	[/#if]
[/#function]

[#--
 * 功能：将系统默认字典的值进行显示
 * 用法 ：${c.dictValue("common.sex","1")}
 *     ${c.dictValue({"1":"你好","2":"你好22"},"1")}
 *     ${c.dictValue([{"value":"1","name":"你好"},{"value":"2","name":"你好22"}],"2","value","name")}
--]
[#function dictValue datas value  key="" text=""]
	[#if datas?is_hash_ex]
	    [#local keys=datas?keys/] 
	    [#list keys as key]
	       [#if key==value]
	          [#return datas[key]]
	       [/#if]
	    [/#list]
    [#elseif datas?is_sequence] [#--is_sequence--]
	    [#list datas as data]  
	        [#if key!=""]  
	            [#if value==data[key]?string]  
	                 [#return data[text]]
	            [/#if]  
	        [#else]  
	            [#if value==data]  
	                [#return data]
	            [/#if]  
	        [/#if]  
	    [/#list] 
    [#elseif  datas?is_string]
		[#local element=rvdict.get(datas)]
		[#if element??]
			[#local items = element.value.items]
			[#if items??]
				[#list items as item] 
					[#if value==item.value]  
	            		[#return item.name]
			        [/#if] 
				[/#list]
			[/#if]
		[/#if]
    [/#if]
[/#function]

[#-- 
 * 功能：showErrors spring改造，判断了status是否存在 与spring一致   
--]
[#macro showErrors separator classOrStyle=""]
    [#if status?? && status.errorMessages??]  
	    [#list status.errorMessages as error]
	    [#if classOrStyle == ""]
	        <b>${error}</b>
	    [#else]
	        [#if classOrStyle?index_of(":") == -1][#assign attr="class"][#else][#assign attr="style"][/#if]
	        <span ${attr}="${classOrStyle}">${error}</span>
	    [/#if]
	    [#if error_has_next]${separator}[/#if]
	    [/#list]
    [/#if]
[/#macro]
[#-- toName 从字典将值转化为名称   --]
[#macro toName datas value  key="" text=""]
   [#if datas?is_hash_ex]
	    [#local keys=datas?keys/] 
	    [#list keys as key]
	       [#if key==value]
	          ${datas[key]}
	          [#break/]
	       [/#if]
	    [/#list]
   [#elseif  datas?is_sequence]  
        [#list datas as data]  
            [#if key!=""]  
                [#if value==data[key]?string]  
                     ${data[text]}
                [#break/]
                [/#if]  
            [#else]  
                [#if value==data]  
                    <option value="${data}" selected> ${data}</option>   
                [#else]  
                    <option value="${data}"]>${data}</option>  
                [/#if]  
            [/#if]  
        [/#list] 
    [#elseif  datas?is_string]
    	[#local element=rvdict.get(datas)]
    	[#if element??]
    		[#local items = element.value.items]
    		[#if items??]
    			[#list items as item] 
    				[#if value==item.value]  
	            		 ${item.name} 
	            		 [#break/]
			        [/#if] 
    			[/#list]
    		[/#if]
    	[/#if]
    [/#if]
[/#macro]
[#--
 * 功能： 输出一个select下拉列表
 * 用法 ：[@c.select("id","common.sex","1")/]
 *     [@c.select({"1":"你好","2":"你好22"},"1")]
 *     [@c.select([{"value":"1","name":"你好"},{"value":"2","name":"你好22"}],"2","value","name")]
--]
[#macro select id datas value="" key="" text="" headkey="" headtext="" attributes="" ]  
    <select id="${id}" name="${id}" ${attributes}>  
    [#if headkey!=""]  
    	<option value="${headkey}">${headtext}</option>
    [/#if]  
    [#if datas?is_hash_ex]
	    [#local keys=datas?keys/]  
	    [#list keys as key]  
	        [#if key==value]  
	            <option value="${key}" selected>${datas[key]}</option> 
	        [#else]  
	            <option value="${key}">${datas[key]}</option>
	        [/#if]  
	    [/#list]  
    [#elseif  datas?is_sequence]  
        [#list datas as data]  
            [#if key!=""]  
                [#if value==data[key]?string]  
                    <option value="${data[key]}" selected> ${data[text]}</option>   
                [#else]  
                    <option value="${data[key]}">${data[text]}</option>  
                [/#if]  
            [#else]  
                [#if value==data]  
                    <option value="${data}" selected> ${data}</option>   
                [#else]  
                    <option value="${data}">${data}</option>  
                [/#if]  
            [/#if]  
        [/#list] 
    [#elseif  datas?is_string]
    	[#local element=rvdict.get(datas)]
    	[#if element??]
    		[#local items = element.value.items]
    		[#if items??]
    			[#list items as item] 
    				[#if value==item.value]  
	            		<option value="${item.value}" selected>${item.name}</option> 
			        [#else]  
			            <option value="${item.value}">${item.name}</option> 
			        [/#if] 
    			[/#list]
    		[/#if]
    	[/#if]
    [/#if]  
    </select>  
[/#macro]  


[#--
 * 功能： 输出一个radios
 * 用法 ：
--]
[#macro radios id datas value="" key="" text="" attributes="" input_attributes=""]  
    <span id="${id}Group"  ${attributes}>  
    [#if datas?is_hash_ex]
	    [#local keys=datas?keys/]  
	    [#list keys as key]  
	        <span>
	        [#if key==value]  
	           <input type="radio" id="${id}_${item_index}" name="${id}" value="${key}" ${input_attributes} checked/> ${datas[key]}
	        [#else]  
	           <input type="radio" id="${id}_${item_index}" name="${id}" value="${key}" ${input_attributes} /> ${datas[key]} 
	        [/#if]  
	        </span>
	    [/#list]  
    [#elseif  datas?is_sequence]  
        [#list datas as data]
            <span>
            [#if key!=""]  
                [#if value==data[key]?string]  
                    <input type="radio" id="${id}_${item_index}" name="${id}" value="${data[key]}" ${input_attributes} checked />${data[text]}
                [#else]  
                    <input type="radio" id="${id}_${item_index}" name="${id}" value="${data[key]}" ${input_attributes} /> ${data[text]}
                [/#if]
            [#else]  
                [#if value==data]  
                    <input type="radio" id="${id}_${item_index}" name="${id}"  value="${data}" ${input_attributes} checked/> ${data} 
                [#else]  
                    <input type="radio" id="${id}_${item_index}" name="${id}"  value="${data}" ${input_attributes} /> ${data}
                [/#if]  
            [/#if]
            </span>
        [/#list] 
    [#elseif  datas?is_string]
    	[#local element=rvdict.get(datas)]
    	[#if element??]
    		[#local items = element.value.items]
    		[#if items??]
    			[#list items as item] 
                    <span>
    				[#if value==item.value]  
	            		<input type="radio" id="${id}_${item_index}" name="${id}"   value="${item.value}" ${input_attributes} checked />${item.name} 
			        [#else]  
			            <input type="radio" id="${id}_${item_index}" name="${id}"   value="${item.value}" ${input_attributes} />${item.name}
			        [/#if]
                    </span>
    			[/#list]
    		[/#if]
    	   
    	[/#if]
    [/#if]  
    </span>  
[/#macro]


[#--
 * 功能： 输出一个checkboxs
 * 用法 ：
--]
[#macro checkboxs id datas values="" attributes="" ]  
    <span id="${id}Group"  ${attributes}>  
    [#if  datas?is_string]
    	[#local element=rvdict.get(datas)]
    	[#if element??]
    		[#local items = element.value.items]
    		[#if items??]
    			[#list items as item] 
    			    <span>
    			    [#if value?is_string]
	    				[#if values==item.value]  
		            		<input type="checkbox" id="${id}_${item_index}" name="${id}"   value="${item.value}" checked />${item.name} 
				        [#else]  
				            <input type="checkbox" id="${id}_${item_index}" name="${id}"   value="${item.value}" />${item.name} 
				        [/#if]
				    [#else] [#-- is list --]
				    	[#if contains(values,item.value)]  
		            		<input type="checkbox" id="${id}_${item_index}" name="${id}"   value="${item.value}" checked/>${item.name} 
				        [#else]  
				            <input type="checkbox" id="${id}_${item_index}" name="${id}"   value="${item.value}" />${item.name} 
				        [/#if]
			        [/#if]
			        <span>
    			[/#list]
    		[/#if]
    	[/#if]
    [/#if]
    </span>
[/#macro]  
 